import $V from './$V';

export default function wad(high, low, close) {
    let wadValue = $V.init(high.length,0);
    let trh = $V.init(high.length,0);
    let trl = $V.init(high.length,0);
    let ad = $V.init(high.length,0);
    for(let i = 0;i < high.length;i++){
        if(i == 0){
            wadValue[i] = 0;
        }
        if(i > 0){
            trh[i] = parseFloat(close[i-1])>parseFloat(high[i])?parseFloat(close[i-1]):parseFloat(high[i]);
            trl[i] = parseFloat(close[i-1])>parseFloat(low[i])?parseFloat(low[i]):parseFloat(close[i-1]);
            if(parseFloat(close[i]) > parseFloat(close[i-1])){
                ad[i] = parseFloat(close[i]) - trl[i];
            }else if(parseFloat(close[i]) < parseFloat(close[i-1])){
                ad[i] = parseFloat(close[i]) - trh[i];
            }else{
                ad[i] =0;
            }
            wadValue[i] = wadValue[i-1] + ad[i];
        }
    }
    return wadValue;
}
